<?php
class Data_Model_GiaoVienMapper extends \Data_Model_DataMapperAbstract {
	
		private static $_instance = null;
		// dung de phan trang
		private $_paginator = null;
		
		public function searchById($magiaovien)
		{
			$db = $this->getDb();
			$selectGiaovien = $db->select()
								->from('tbl_giaovien')
								->where('MaGiaoVien = ?',$magiaovien);
			$giaovien = $db->fetchRow($selectGiaovien);
		
			return $this->_populate($giaovien);
		}
		
		public function giaovienList()
		{
			$db = $this->getDb();
			$selectGiaovien = $db->select()
								->from('tbl_giaovien');
			$giaoviens = $db->fetchAll($selectGiaovien);
			$giaovienObjArray = array();
			foreach($giaoviens as $giaovien)
			{
				$giaovienObjArray[] = $this->_populate($giaovien);
			}
			return $giaovienObjArray;
		}
	/* (non-PHPdoc)
	 * @see Data_Model_DataMapperAbstract::_insert()
	 */protected function _insert(Data_Model_DomainObjectAbstract $obj) {
		// TODO Auto-generated method stub
		$db = $this->getDb();
		$data = array(
				'TenGiaoVien' => $obj->getTengiaovien(),
				'NamSinh' => $obj->getNamsinh(),
				'QueQuan' => $obj->getQuequan(),
				'ChuyenMon' => $obj->getChuyenmon(),
				'TrinhDo' => $obj->getTrinhdo(),
				'NgayVaoLam' => $obj->getNgayVaoLam(),
				'Email' => $obj->getEmail()
		);
		$db->insert('tbl_giaovien',$data);
		
		}

	/* (non-PHPdoc)
	 * @see Data_Model_DataMapperAbstract::_update()
	 */protected function _update(Data_Model_DomainObjectAbstract $obj) {
		// TODO Auto-generated method stub
		$db = $this->getDb();
		$data = array(
				'TenGiaoVien' => $obj->getTengiaovien(),
				'NamSinh' => $obj->getNamsinh(),
				'QueQuan' => $obj->getQuequan(),
				'ChuyenMon' => $obj->getChuyenmon(),
				'TrinhDo' => $obj->getTrinhdo(),
				'NgayVaoLam' => $obj->getNgayVaoLam(),
				'Email' => $obj->getEmail()
		);
		$where = $db->quoteInto('MaGiaoVien = ?',$obj->getId());
		$db->update('tbl_giaovien',$data,$where);
		
		}

	/* (non-PHPdoc)
	 * @see Data_Model_DataMapperAbstract::_populate()
	 */protected function _populate($data) {
		// TODO Auto-generated method stub
		$obj = new Data_Model_GiaoVien();
		$obj->setId($data['MaGiaoVien']);
		$obj->setTengiaovien($data['TenGiaoVien']);
		$obj->setNamsinh($data['NamSinh']);
		$obj->setQuequan($data['QueQuan']);
		$obj->setChuyenmon($data['ChuyenMon']);
		$obj->setTrinhdo($data['TrinhDo']);
		$obj->setNgayvaolam($data['NgayVaoLam']);
		$obj->setEmail($data['Email']);
		
		return $obj;
		}

		public function delete($id)
		{
			$db = $this->getDb();
			$where = $db->quoteInto('MaGiaoVien = ?',$id);
			$db->delete('tbl_giaovien',$where);
		}
		
		// Goi chinh no
		
		public static function getInstance()
		{
			if(null === self::$_instance)
			{
				self::$_instance = new self();
			}
			return self::$_instance;
		}
}

?>